
<!DOCTYPE HTML>
<html lang="zh-cn" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>URL 是单页应用的精华 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Service-layer.html" />
    
    
    <link rel="prev" href="State-management.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="輸入並搜尋" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    总览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../Getting-started.html">
            
                <a href="../Getting-started.html">
            
                    
                    开始
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../Features.html">
            
                <a href="../Features.html">
            
                    
                    技术栈
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../Structure.html">
            
                <a href="../Structure.html">
            
                    
                    目录结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="./">
            
                <a href="./">
            
                    
                    深入了解
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="State-management.html">
            
                <a href="State-management.html">
            
                    
                    谈状态管理
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.2" data-path="URL-is-soul-of-SPA.html">
            
                <a href="URL-is-soul-of-SPA.html">
            
                    
                    URL 是单页应用的精华
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="Service-layer.html">
            
                <a href="Service-layer.html">
            
                    
                    引入服务层
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="Ajax-interface.html">
            
                <a href="Ajax-interface.html">
            
                    
                    Ajax 接口化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="Configuration.html">
            
                <a href="Configuration.html">
            
                    
                    配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="CORS-and-Proxy.html">
            
                <a href="CORS-and-Proxy.html">
            
                    
                    跨域与代理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="Best-practice.html">
            
                <a href="Best-practice.html">
            
                    
                    最佳实践
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <a target="_blank" href="https://github.com/kenberkeley/vue-demo/issues">
            
                    
                    问题反馈（issues）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <a target="_blank" href="https://github.com/kenberkeley/vue-demo/releases">
            
                    
                    版本迭代（releases）
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本書使用 GitBook 釋出
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >URL 是单页应用的精华</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#xA7;-url-&#x662F;&#x5355;&#x9875;&#x5E94;&#x7528;&#x7684;&#x7CBE;&#x534E;">&#xA7; URL &#x662F;&#x5355;&#x9875;&#x5E94;&#x7528;&#x7684;&#x7CBE;&#x534E;</h1>
<p>&#x5728;&#x4E0A;&#x7BC7;<a href="State-management.html"><strong>&#x8C08;&#x72B6;&#x6001;&#x7BA1;&#x7406;</strong></a>&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x603B;&#x7ED3;&#x4E86;&#x6CA1;&#x6709;&#x5F15;&#x5165; Vuex &#x7684;&#x539F;&#x56E0;<br>&#x5176;&#x5B9E;&#x8FD8;&#x6709;&#x4E00;&#x4E2A;&#x5F88;&#x91CD;&#x8981;&#x7684;&#x539F;&#x56E0;&#xFF1A;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x4E86; <code>vue-router</code>&#xFF0C;&#x53EF;&#x4EE5;&#x5B8C;&#x5168;&#x638C;&#x63A7; URL &#x4EE5;&#x8868;&#x793A;&#x5E94;&#x7528;&#x7684;&#x72B6;&#x6001;</p>
<p>&#x4F8B;&#x5982;&#xFF0C;&#x6211;&#x4EEC;&#x5728; Google &#x8F93;&#x5165;&#x6846;&#x8F93;&#x5165; <code>vue</code>&#xFF0C;&#x6572;&#x4E0B;&#x56DE;&#x8F66;&#xFF0C;&#x5C31;&#x8DF3;&#x8F6C;&#x5230;&#x4E86;&#x641C;&#x7D22;&#x7ED3;&#x679C;&#x7684;&#x9875;&#x9762;&#xFF0C;&#x6B64;&#x65F6; URL &#x662F;&#xFF1A;<br><code>https://www.google.com/?gws_rd=cr,ssl#newwindow=1&amp;safe=strict&amp;q=vue</code><br>&#x5173;&#x952E;&#x70B9;&#x662F;&#xFF1A;<code>{ q: &apos;vue&apos; }</code></p>
<p>&#x70B9;&#x51FB;&#x4E0B;&#x4E00;&#x9875;&#xFF08;&#x7B2C; 2 &#x9875;&#xFF09;&#xFF1A;<br><code>https://www.google.com/?gws_rd=cr,ssl#q=vue&amp;newwindow=1&amp;safe=strict&amp;start=10</code><br>&#x5173;&#x952E;&#x70B9;&#x662F;&#xFF1A;<code>{ q: &apos;vue&apos;, start: 10 }</code></p>
<p>&#x518D;&#x70B9;&#x51FB;&#x4E0B;&#x4E00;&#x9875;&#xFF08;&#x7B2C; 3 &#x9875;&#xFF09;&#xFF1A;<br><code>https://www.google.com/?gws_rd=cr,ssl#q=vue&amp;newwindow=1&amp;safe=strict&amp;start=20</code><br>&#x5173;&#x952E;&#x70B9;&#x662F;&#xFF1A;<code>{ q: &apos;vue&apos;, start: 20 }</code></p>
<p>&#x65E2;&#x7136;&#x6211;&#x4EEC;&#x53D1;&#x73B0;&#x4E86;&#x8FD9;&#x79CD;&#x89C4;&#x5F8B;&#xFF0C;&#x90A3;&#x4E48;&#x4F7F;&#x7528;&#x7A7A;&#x767D;&#x6807;&#x7B7E;&#x9875;&#x76F4;&#x63A5;&#x8BBF;&#x95EE;&#xFF1A;<br><code>https://www.google.com/?gws_rd=cr,ssl#q=vue&amp;newwindow=1&amp;safe=strict&amp;start=30</code><br>&#x663E;&#x7136;&#x5C31;&#x662F;&#x7B2C; 4 &#x9875;&#x7684;&#x641C;&#x7D22;&#x7ED3;&#x679C;&#x3002;&#x800C;&#x4E14;&#x6BEB;&#x65E0;&#x7591;&#x95EE;&#x5730;&#xFF0C;&#x641C;&#x7D22;&#x6846;&#x4F1A;&#x4ECE; URL &#x4E2D;&#x63D0;&#x53D6;&#x5BF9;&#x5E94;&#x7684;&#x5173;&#x952E;&#x5B57;&#x8FDB;&#x884C;<strong>&#x540C;&#x6B65;</strong></p>
<p>&#x7EFC;&#x4E0A;&#xFF1A;URL &#x53EF;&#x4EE5;&#x8868;&#x73B0;&#x5E94;&#x7528;&#x7684;&#x72B6;&#x6001;&#xFF0C;&#x800C;&#x4E14;&#x5728;&#x4E00;&#x5B9A;&#x7A0B;&#x5EA6;&#x4E0A;&#xFF0C;URL &#x5C31;&#x662F;&#x5E94;&#x7528;&#x72B6;&#x6001;&#x7684;<strong>&#x6700;&#x4F73;&#x8868;&#x73B0;&#x5F62;&#x5F0F;</strong></p>
<hr>
<h3 id="&#x5355;&#x9875;&#x5E94;&#x7528;&#x7684;&#x7CBE;&#x534E;&#x5728;&#x4E8E;&#xFF1A;">&#x5355;&#x9875;&#x5E94;&#x7528;&#x7684;&#x7CBE;&#x534E;&#x5728;&#x4E8E;&#xFF1A;</h3>
<p>&#x62E5;&#x6709;&#x65E0;&#x7F1D;&#x5207;&#x6362;&#x4F53;&#x9A8C;&#x7684;&#x540C;&#x65F6;&#xFF0C;&#x4FDD;&#x8BC1; URL &#x4E0E;&#x9875;&#x9762;&#x72B6;&#x6001;&#x7684;&#x540C;&#x6B65;&#x6027;&#xFF0C;&#x6EE1;&#x8DB3;&#x4FDD;&#x5B58;&#x4E66;&#x7B7E;&#x3001;&#x5F3A;&#x5236;&#x5237;&#x65B0;&#x3001;&#x524D;&#x8FDB;&#x56DE;&#x9000;&#x7B49;&#x57FA;&#x672C;&#x9700;&#x6C42;<br>&#xFF08;&#x81F3;&#x4E8E;&#x540C;&#x6B65;&#x7684;&#x7C92;&#x5EA6;&#x9700;&#x8981;&#x7EC6;&#x81F4;&#x5230;&#x4EC0;&#x4E48;&#x7A0B;&#x5EA6;&#xFF0C;&#x5C31;&#x9700;&#x8981;&#x6839;&#x636E;&#x5B9E;&#x9645;&#x60C5;&#x51B5;&#x81EA;&#x884C;&#x659F;&#x914C;&#x4E86;&#xFF09;</p>
<blockquote>
<p>&#x4F8B;&#x5982;&#xFF0C;<a href="https://github.com/kenberkeley" target="_blank">https://github.com/kenberkeley</a> &#x8868;&#x793A; kenberkeley &#x7684;&#x9996;&#x9875;<br>&#x53C8;&#x4F8B;&#x5982;&#xFF0C;<a href="https://github.com/kenberkeley/vue-demo/issues/1" target="_blank">https://github.com/kenberkeley/vue-demo/issues/1</a> &#x8868;&#x793A; vue-demo &#x7684;&#x7B2C;&#x4E00;&#x4E2A; issue</p>
<p>&#x5C31;&#x8FDE;&#x5FAE;&#x4FE1;&#x8FD9;&#x79CD;&#x539F;&#x751F; APP&#xFF0C;&#x4E5F;&#x6709;&#x4F7F;&#x7528; URL &#x8868;&#x793A;&#x5E94;&#x7528;&#x7684;&#x72B6;&#x6001;&#xFF08;URL Schemes&#xFF09;<br>&#x4F8B;&#x5982;&#x8BBF;&#x95EE; <code>weixin://dl/moments</code> &#x5C31;&#x4F1A;&#x8DF3;&#x8F6C;&#x5230;&#x670B;&#x53CB;&#x5708;&#x9875;&#x9762; (&#x4E0D;&#x8FC7;&#x5F53;&#x524D;&#x5FAE;&#x4FE1;&#x5DF2;&#x5C4F;&#x853D;&#x6389;&#x8FD9;&#x7C7B;&#x94FE;&#x63A5;&#x7684;&#x8BBF;&#x95EE;)</p>
</blockquote>
<hr>
<p><code>vue-router</code> &#x63D0;&#x4F9B;&#x7684; <a href="https://github.com/vuejs/vue-router/blob/1.0/docs/zh-cn/pipeline/data.md" target="_blank"><code>data</code></a> &#x51FD;&#x6570;&#xFF0C;&#x6781;&#x5176;&#x65B9;&#x4FBF;&#x5730;&#x8BA9;&#x6211;&#x4EEC;&#x54CD;&#x5E94; URL &#x7684;&#x53D8;&#x5316;&#x4EE5;&#x8FDB;&#x884C; xhr &#x8BF7;&#x6C42;<br>&#x5F53;&#x7136;&#xFF0C;&#x5982;&#x679C;&#x5E76;&#x975E;&#x8DEF;&#x7531;&#x9875;&#x9762;&#x7EC4;&#x4EF6;&#xFF0C;&#x662F;&#x4E0D;&#x80FD;&#x591F;&#x4EAB;&#x53D7;&#x5230; <code>data</code> &#x51FD;&#x6570;&#x7684;&#x4FBF;&#x5229;<br>&#x4E0D;&#x8FC7;&#x6211;&#x4EEC;&#x4ECD;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x8BA1;&#x7B97;&#x5C5E;&#x6027;&#x6765;&#x5B9E;&#x73B0;&#x540C;&#x6837;&#x7684;&#x529F;&#x80FD;&#xFF1A;</p>
<pre><code class="lang-js">watch: {
  <span class="hljs-string">&apos;$route.query&apos;</span> (query, oldQuery) {
     <span class="hljs-comment">// ...</span>
   }
}
</code></pre>
<hr>
<p>&#x7531;&#x4E8E;&#x6211;&#x4EEC;&#x6CA1;&#x6709;&#x5F15;&#x5165; Vuex&#xFF0C;&#x56E0;&#x6B64;&#x4E0D;&#x80FD;&#x4F7F;&#x7528; <a href="https://github.com/vuejs/vuex-router-sync" target="_blank">vuex-router-sync</a> &#x6765;&#x81EA;&#x52A8;&#x540C;&#x6B65;&#x8DEF;&#x7531;&#x4E0E;&#x7EC4;&#x4EF6;&#x7684;&#x72B6;&#x6001;<br>&#x4F46;&#x7A0D;&#x5FAE;&#x5C01;&#x88C5;&#x4E00;&#x4E0B;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x5B8C;&#x5168;&#x6EE1;&#x8DB3;&#x6211;&#x4EEC;&#x7684;&#x9700;&#x6C42;&#xFF08;&#x8BE6;&#x60C5;&#x8BF7;&#x89C1; <code>src/mixins/autoSyncWithQuery.js</code>&#xFF09;  </p>
<blockquote>
<p>&#x4E0A;&#x8FF0; <code>autoSyncWithQuery</code> &#x7684;&#x539F;&#x7406;&#x76F8;&#x5F53;&#x7B80;&#x5355;&#xFF1A;<br><strong>&#x7EA6;&#x5B9A;</strong>&#x7EC4;&#x4EF6; <code>data</code> &#x5C5E;&#x6027;&#x4E2D;&#x540E;&#x7F00;&#x5E26; <code>$</code> &#x7684;&#x5B57;&#x6BB5;&#xFF0C;&#x4F7F;&#x7528; <code>$watch</code> &#x540C;&#x6B65;&#x5176;&#x53D8;&#x5316;&#x5230; query string<br>&#x540C;&#x65F6;&#xFF0C;&#x4E5F;&#x5BF9; <code>$route.query</code> &#x8BBE;&#x7F6E; <code>$watch</code>&#xFF0C;&#x540C;&#x6B65;&#x5176;&#x53D8;&#x5316;&#x5230;&#x5BF9;&#x5E94;&#x7684;&#x7EC4;&#x4EF6;&#x672C;&#x5730;&#x72B6;&#x6001;</p>
<p>&#x7279;&#x522B;&#x6CE8;&#x610F;&#xFF1A;&#x7531;&#x4E8E;&#x72B6;&#x6001;&#x4E0E;&#x8DEF;&#x7531;&#x662F;&#x53CC;&#x5411;&#x540C;&#x6B65;&#x7684;&#xFF0C;&#x56E0;&#x6B64;<strong>&#x5B89;&#x5168;&#x6027;</strong>&#x662F;&#x5FC5;&#x987B;&#x8003;&#x91CF;&#x7684;</p>
</blockquote>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="State-management.html" class="navigation navigation-prev " aria-label="Previous page: 谈状态管理">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Service-layer.html" class="navigation navigation-next " aria-label="Next page: 引入服务层">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"URL 是单页应用的精华","level":"1.5.2","depth":2,"next":{"title":"引入服务层","level":"1.5.3","depth":2,"path":"development/Service-layer.md","ref":"development/Service-layer.md","articles":[]},"previous":{"title":"谈状态管理","level":"1.5.1","depth":2,"path":"development/State-management.md","ref":"development/State-management.md","articles":[]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"language":"zh-cn","gitbook":"*"},"file":{"path":"development/URL-is-soul-of-SPA.md","mtime":"2017-02-07T06:25:58.175Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-02-07T06:28:34.135Z"},"basePath":"..","book":{"language":"zh-cn"}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

